$().ready(function() {
	validateRule();
    $("#grade").val($("#hiddenId2").val());
    $("#state").val($("#hiddenId3").val())
});

$.validator.setDefaults({
	submitHandler : function() {
		update();
	}
});
function update() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/jzweb/certificateNews/update",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm").validate({
        rules : {
            profileId : {
                required : true
            },
            grade : {
                required : true
            },
            relatedMajors : {
                required : true
            },
            examFee : {
                required : true
            },
            state: {
                required : true
            }
        },
        messages : {
            profileId : {
                required : icon + "请选择证书"
            },
            grade : {
                required : icon + "请选择证书等级"
            },
            relatedMajors : {
                required : icon + "请输入相关专业"
            },
            examFee : {
                required : icon + "请输入考试费用"
            },
            state : {
                required : icon + "请输入选择状态"
            }
        }
    })
}

layui.use('upload', function () {
    var upload = layui.upload;
    upload.render({
        elem: '#btnUpload',
        url: '/common/sysFile/upload',
        accept: 'images', //只允许上传图片
        acceptMime: 'image/*', //只筛选图片
        done: function (r) {
            $("#certificateImg").val(r.data);
            $("#img").attr("src",r.data)
        },
        error: function (r) {
            layer.msg(r.msg);
        }
    });
});